<template>
  <div class="cinema">
    <top-bar>
      <template #left>
        <div @click="toCity">
          <current-city />
          <i class="iconfont icon-xia"></i>
        </div>
      </template>
      <template #center>
        <span>影院</span>
      </template>
      <template #right>
        <i class="iconfont icon-fangdajing"></i>
      </template>
    </top-bar>

    <b-scroll
      class="wrapper"
      ref="wrapper"
      :data="moviesList"
      :pullDown="true"
      @pullDown="pullDown"
      :scrollEnd="true"
      @scrollEnd="scrollEnd"
    >
      <ul class="cinema-list">
        <li v-for="(item, index) in moviesList" :key="item.cinemaId">
          <div class="left">
            <span class="name">{{ item.name }}</span>
            <span class="address">{{ item.address }}</span>
          </div>
          <div class="right">
            <span class="price">¥ {{ item.lowPrice | priceSplice }} 起</span>
            <p>{{ index }}</p>
          </div>
        </li>
      </ul>
    </b-scroll>
  </div>
</template>

<script>
import TopBar from "@/components/TopBar";
import BScroll from "@/components/BScroll";
import CurrentCity from "@/components/CurrentCity";
import { getCinemaAPI } from "@/network/api";

export default {
  name: "Cinema",
  data() {
    return {
      moviesList: [],
      cityId: localStorage.getItem("cityId"),
    };
  },
  filters: {
    priceSplice(val) {
      let str = val + "";
      return str.slice(0, -2) + "." + str.slice(-2);
    },
  },
  components: {
    TopBar,
    BScroll,
    CurrentCity,
  },
  methods: {
    pullDown() {
      console.log("下拉了");
    },
    scrollEnd() {
      console.log("上");
    },
    backClick() {
      // 通过坐标跳转
      this.$refs.wrapper.scrollTo(0, 0, 1000);
    },
    toCity() {
      this.$router.push("/city");
    },
  },
  mounted() {
    this.cityId = localStorage.getItem("cityId") || 110100;
    getCinemaAPI({
      cityId: this.cityId,
      ticketFlag: 1,
      k: 2783633,
    }).then((res) => {
      this.moviesList = res.data.data.cinemas;
    });
  },
};
</script>

<style scoped  lang="less" >
.wrapper {
  height: calc(100vh - 44px - 49px);
}
.cinema-list {
  background-color: #fff;
  li {
    padding: 10px 20px;
    border-bottom: 1px solid #aaa;
    display: flex;
    justify-content: space-between;
    .left {
      width: 220px;
      display: flex;
      flex-direction: column;
      span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .address {
        color: #797d82;
        font-size: 12px;
      }
    }
    .right {
      width: 70px;
      text-align: right;
      .price {
        color: #ff5f16;
      }
    }
  }
}
</style>